package com.sure0000.basic;

import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.HttpClients;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.stream.Collectors;

/**
 * @program: demo
 * @description: apache http client
 * @author: xuyouchang@supcon.com
 * @create: 2019-12-26 13:52
 **/
public class ApacheHttp {

    public static void main(String[] args) throws IOException {
        HttpClient httpClient = HttpClients.createDefault();
        HttpGet get = new HttpGet("https://www.baidu.com");
        HttpResponse response = httpClient.execute(get);
        System.out.println(response.getStatusLine());
        System.out.println(new BufferedReader(new InputStreamReader(response.getEntity().getContent())).lines().collect(Collectors.joining()));
    }
}
